'use strict'

var Koa=require('koa')
var sha1 = require('sha1');
var config = {
	wechat :{
		appID:'ssdasdas',
		appSecret:'asdasd'.
		token:'sadasdasdas'
	}
}
var app = new Koa()
app.use(function *(next){
	
	console.log(this.query);
	var token = config.wechat.token
	var signature = this.query.signature
	var nonce = this.query.nonce
	var timestamp = this.query.timestamp
	var ecostr = this.query.ecostr
	var str = [token,timestamp,nonce].sort().join('')
	var sha = sha1(str);

	if(sha===signature){
		this.body = ecostr + ''
	}else{

		this.body = 'wrong'
	}
});

app.listen(1234)
console.info("Listening:1234");